package taobao.config;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TaoBaoItemConfig {
    private int activityId;
    private int itemId;
    private int type;
    private String icon;
    private int sellNpc;
    private String positions;
    private List<TaoBaoLabelPositionConfig> positionConfigs = new ArrayList<>();

    private String posNpc;

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public int getItemId() {
        return itemId;
    }

    public void setItemId(int itemId) {
        this.itemId = itemId;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public int getSellNpc() {
        return sellNpc;
    }

    public void setSellNpc(int sellNpc) {
        this.sellNpc = sellNpc;
    }

    public String getPositions() {
        return positions;
    }

    public String getPosNpc() {
        return posNpc;
    }

    public void setPosNpc(String posNpc) {
        this.posNpc = posNpc;
    }

    public void setPositions(String positions) {
        this.positions = positions;
        String[] arr = positions.split("\\|");
        for (int i = 0; i < arr.length; i++) {
            int face = i + 1;
            String s = arr[i];
            String[] split = s.split("-");
            for (String str : split) {
                String[] sarr = str.split(";");
                int x = Integer.parseInt(sarr[0]);
                int y = Integer.parseInt(sarr[1]);
                TaoBaoLabelPositionConfig taoBaoLabelPositionConfig = new TaoBaoLabelPositionConfig(face, x, y);
                positionConfigs.add(taoBaoLabelPositionConfig);
            }
        }
    }

    public int getMaxLabelSize() {
        return positionConfigs.size();
    }

    public int getLabelSizeByFace(int face) {
        int num = 0;
        for (TaoBaoLabelPositionConfig config : positionConfigs) {
            if (config.getFace() == face) {
                num++;
            }
        }
        return num;
    }


    public Map<Integer, Integer> getFaceNumMap() {
        Map<Integer, Integer> paramMap = new HashMap<>();
        for (TaoBaoLabelPositionConfig config : positionConfigs) {
            int face = config.getFace();
            Integer value = paramMap.getOrDefault(face, 0);
            paramMap.put(face, value + 1);
        }
        return paramMap;
    }

    public List<TaoBaoLabelPositionConfig> getPositionsByFaceId(Integer faceId) {
        List<TaoBaoLabelPositionConfig> positionConfigList = new ArrayList<>();
        for (TaoBaoLabelPositionConfig positionConfig : positionConfigs) {
            if (positionConfig.getFace() == faceId) {
                positionConfigList.add(positionConfig);
            }
        }
        return positionConfigList;
    }
}
